import * as mobx from 'mobx';
import { observable, action, computed, asMap } from 'mobx';
import { WeaTableNew } from 'comsMobx';
const { TableStore } = WeaTableNew;
import { getWFList } from '../apis/api';

export default class Store{
    baseParam = {};
    @observable tabKey = "0";
    @observable tableStoreMap = observable.map ? observable.map({}) : asMap({});
    @computed get tableStore(){
        return this.tableStoreMap.has(this.tabKey) ? this.tableStoreMap.get(this.tabKey) : new TableStore();
    }
    @observable dataSource = []
    @observable allCounts

    constructor(){
        this.setBaseParam = this.setBaseParam;
        this.switchTab = this.switchTab;
    }

    @action
    setBaseParam = (params={}) => {
        this.baseParam = params;
    }

    @action
    appendTableStoreMap = (obj) => {
        this.tableStoreMap.set(this.tabKey, obj);
    }

    @action('切换tab')
    switchTab = (key) => {
        this.tabKey = key.toString();
        if(!this.tableStoreMap.has(this.tabKey))
            this.loadData();
    }

    @action('加载数据')
    loadData = (commonParam) => {
        const params = {...this.baseParam, ...{tabindex:1}};
        // let params = {requestid:commonParam.requestid}
	    getWFList(params).then(res =>{
            this.dataSource = res.data;
            this.allCounts = res.count;
		});
    }

}